package com.diamond.web.controller.system;

import java.util.List;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.diamond.core.entity.Result;
import com.diamond.web.controller.GenericController;
import com.diamond.web.model.system.Role;
import com.diamond.web.service.system.RoleService;

//@RequestMapping("admin/role")
//@Controller
public class TemplateController extends GenericController{

	
	@Resource
	RoleService roleService;
	
	@RequestMapping("list")
	public ModelAndView toList(){
		ModelAndView mv  = getModelAndView("list");
		return mv;
	}
	
	@RequestMapping("add")
	public ModelAndView toAdd(){
		ModelAndView mv = getModelAndView("save");
		return mv;
	}

	@RequestMapping("edit")
	public ModelAndView toEdit(Long id){
		ModelAndView mv = getModelAndView("save");
		mv.addObject("m", roleService.selectById(id));
		return mv;
	}
	
	@RequestMapping("addData")
	@ResponseBody
	public Result addData(@Valid Role model,BindingResult validResult){
		Result result = new Result();
		roleService.insert(model);
		result.setSuccess(true);
		return result;
	}
	
	@RequestMapping("editData")
	@ResponseBody
	public Result editData(@Valid Role model,BindingResult validResult){
		Result result = new Result();
		roleService.update(model);
		result.setSuccess(true);
		return result;
	}
	
	@RequestMapping("delete")
	@ResponseBody 
	public Result delete(Long id){
		Result result =new Result();
		roleService.deleteById(id);
		result.setSuccess(true);
		return result;
	}
	
	@RequestMapping("listData")
	@ResponseBody
	public List<Role> list() {
		return roleService.selectList();
	}
	
	
	
}
